#pragma once

#include <stdio.h>

namespace bridge {
    
/// @brief 实现化角色, 定义实现化角色的接口
class AbstractImplementor {
public:
    virtual ~AbstractImplementor() {}
    virtual void Request() = 0;
};

/// @brief 具体实现化角色, 给出实现化角色接口的具体实现
class ConcreteImplementorA : public AbstractImplementor {
public:
    virtual void Request() {
        printf("this ConcreteImplementorA::Request!\n");
    }
};
class ConcreteImplementorB : public AbstractImplementor {
public:
    virtual void Request() {
        printf("this ConcreteImplementorB::Request!\n");
    }
};

/// @brief 抽象类角色, 对实现化对象的引用
class AbstractRole {
public:
    AbstractRole(AbstractImplementor* impl) : impl_(impl) {}
    virtual ~AbstractRole() {}

    virtual void Request() = 0;
    
protected:
    AbstractImplementor* impl_;
};

/// @brief 扩展抽象化角色, 实现父类中的业务方法
class ExtendRole : public AbstractRole {
public:
    ExtendRole(AbstractImplementor* impl) : AbstractRole(impl) {}

    virtual void Request() {
        impl_->Request();
    }
};

} // namespace bridge

void Test_08_bridge_impl_2() {
    printf("-------------------- %s --------------------\n", __FUNCTION__);
    bridge::AbstractImplementor* ptr_impl = new bridge::ConcreteImplementorA();
    bridge::AbstractRole* ptr_role = new bridge::ExtendRole(ptr_impl);
    ptr_role->Request();
    delete ptr_role;
    delete ptr_impl;
}

// -------------------- Test_08_bridge_impl_2 --------------------
// this ConcreteImplementorA::Request!